package com.springboot.web;

import com.springboot.model.Student;
import javafx.scene.chart.ValueAxis;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@Controller
@RestController //相当于控制层类上加@Controller + 方法上加@ResponseBody
                //意味着当前控制层类中所有方法返回的都是json对象
public class StudentController {

    @RequestMapping(value = "/student")
//    public @ResponseBody Object student(){
    public Object student(){
        Student student = new Student();
        student.setId(1001);
        student.setName("Zhangsan");
        return  student;
    }
    //该方法请求方式支持GET和POST请求
    @RequestMapping(value = "/queryStudentById",method = {RequestMethod.GET,RequestMethod.POST})
    public Object queryStudentById(Integer id){
        Student student =new Student();
        student.setId(id);
        return student;
    }

//    @RequestMapping(value = "/queryStudentById2",method = {RequestMethod.GET})
    @GetMapping(value = "/queryStudentById2")//相当于上一句话，只接受get请求，如果请求方式不对会报405错误
    //该注解通常在查询数据的时候使用 ->查询
    public Object queryStudentById2(Integer id){
        return "Only GET method";
    }
//    @RequestMapping(value = "/insert",method = {RequestMethod.POST})
    @PostMapping(value ="/insert")//相当于上一句话，只接受post请求，如果请求方式不对会报405错误
    //该注解通常在新增数据的时候使用 ->新增
    public Object insert(){
        return "insert sucess";
    }

//    @RequestMapping(value = "delete",method = RequestMethod.DELETE)
    @DeleteMapping(value = "delete")
    //该注解通常在删除数据的时候使用 ->删除
    public Object delete(){
        return "delete Student";
    }

//    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @PutMapping(value = "/update")
    //该注解通常在修改数据的时候使用e ->更新
    public Object upda(){
        return "update student info";
    }
}
